package com.www.dao;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.www.domain.Account;

/**
 * 客户dao
 */
@Repository
public interface AccountDao {
	/*
	 * 客户插入操作
	 */
	@Insert("insert into account(id,name,password,realName,idCard,mobile,address,status) values(default,#{name},#{password},#{realName},#{idCard},#{mobile},#{address},#{status})")
	public int add(Account account);
	
	/*
	 * 客户编辑操作
	 */
	@Update("update account set name = #{name},password = #{password},realName = #{realName},idCard = #{idCard},mobile = #{mobile},address = #{address},status = #{status} where id = #{id}")
	public int edit(Account account);
	
	/*
	 * 客户删除操作
	 */
	@Delete("delete from account where id = ${value}")
	public int delete(Long id);
	
	/*
	 * 模糊搜索总条数
	 */
	@Select({"<script> "+
			"select count(*) from account " +
			"where 1=1 " +
			"<if test='name != null'> and name like '%${name}%'</if>" +
			"<if test='status != null'> and status like '%${status}%'</if>" +
			"<if test='realName != null'> and realName like '%${realName}%'</if>" +
			"<if test='idCard != null'> and idCard like '%${idCard}%'</if>" +
			"<if test='mobile != null'> and mobile like '%${mobile}%'</if>" +
	 		"</script>"})
	public Integer getTotal(Map<String, Object> queryMap);
	
	/*
	 * 客户信息搜索查询
	 */
	@Select({"<script>" +
			"select * from account " +
			"where  1=1 " +
			"<if test='name != null'> and name like '%${name}%'</if>" +
			"<if test='status != null'> and status like '%${status}%'</if>" +
			"<if test='realName != null'> and realName like '%${realName}%'</if>" +
			"<if test='idCard != null'> and idCard like '%${idCard}%'</if>" +
			"<if test='mobile != null'> and mobile like '%${mobile}%'</if>" +
			"<if test='offset != null and pageSize != null'> limit #{offset},#{pageSize}</if>" +
		"</script>"})
	public List<Account> findList(Map<String, Object> queryMap);
	
	/*
	 * 获取单个客户信息
	 */
	@Select("select * from account where id = #{value}")
	public Account find(Long id);
	
	/*
	 * 根据用户名获取客户信息 
	 */
	@Select("select * from account where name = #{value}")
	public Account findByName(String name);
	
	/*
	 * 获取所有客户信息
	 */
	@Select("select * from account")
	public List<Account> findAll();
}
